﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Syntax_GUI
{
    public partial class CompilerGUI : Form
    {

        private string FilePath;

        public CompilerGUI GetRef()
        {
            return this;
        }
        
        public CompilerGUI()
        {
            InitializeComponent();
        }

        private void CompilerGUI_Load(object sender, EventArgs e)
        {
           
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            this.FilePath = openFileDialog1.FileName;
            if (!String.IsNullOrEmpty(this.FilePath))
            {
                string FileData = System.IO.File.ReadAllText(this.FilePath);
                EditorTextBox.Text = FileData;
            }
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(this.FilePath))
            {
                string FileData = EditorTextBox.Text;
                System.IO.File.WriteAllText(this.FilePath, FileData);
            }
            else
            {
                saveAsToolStripMenuItem_Click(sender, e);
            }
        }

        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            saveFileDialog1.ShowDialog();
            this.FilePath = saveFileDialog1.FileName;
            string FileData = EditorTextBox.Text;
            if (!String.IsNullOrEmpty(this.FilePath))
            {
                System.IO.File.WriteAllText(this.FilePath, FileData);
            }
        }

        private void openToolStripButton_Click_1(object sender, EventArgs e)
        {
            openToolStripMenuItem_Click(sender, e);
        }

        private void saveToolStripButton_Click_1(object sender, EventArgs e)
        {
            saveToolStripMenuItem_Click(sender, e);
        }

        private void newToolStripButton_Click(object sender, EventArgs e)
        {
            this.EditorTextBox.Clear();
            this.FilePath = null;
        }

        private void lexicToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Control control = new Control(this.GetRef());
            control.DoLexical();
        }

        private void syntaxToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Control control = new Control(this.GetRef());
            control.DoParse();
        }
    }
}
